package com.woniuxy.joylife.manager.controller;

import com.woniuxy.common.constant.ManagerConstant;
import com.woniuxy.common.utils.KeyUtil;
import com.woniuxy.common.validate.AddGroup;
import com.woniuxy.common.validate.UpdateGroup;
import com.woniuxy.joylife.manager.utils.PageUtils;
import com.woniuxy.joylife.manager.utils.R;
import com.woniuxy.joylife.manager.entity.EstatesDetailEntity;
import com.woniuxy.joylife.manager.service.EstatesDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;


/**
 * 
 *
 * @author renxiang
 * @email 981405195@qq.com
 * @date 2020-05-02 17:48:46
 */
@RestController
@RequestMapping("manager/estatesdetail")
public class EstatesDetailController {
    @Autowired
    private EstatesDetailService estatesDetailService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("manager:estatesdetail:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = estatesDetailService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{estId}")
    //@RequiresPermissions("manager:estatesdetail:info")
    public R info(@PathVariable("estId") String estId){
		EstatesDetailEntity estatesDetail = estatesDetailService.getById(estId);

        return R.ok().put("estatesDetail", estatesDetail);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("manager:estatesdetail:save")
    public R save(@Validated({AddGroup.class})@RequestBody EstatesDetailEntity estatesDetail){
        estatesDetail.setEstId(KeyUtil.generateKey());
        estatesDetail.setCreatetime(new Date());
        estatesDetail.setState(ManagerConstant.UNDELETED);
		estatesDetailService.save(estatesDetail);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("manager:estatesdetail:update")
    public R update(@Validated({UpdateGroup.class}) @RequestBody EstatesDetailEntity estatesDetail){
        estatesDetail.setUpdatetime(new Date());
		estatesDetailService.updateById(estatesDetail);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("manager:estatesdetail:delete")
    public R delete(@RequestBody String[] estIds){
		estatesDetailService.removeByIds(Arrays.asList(estIds));

        return R.ok();
    }

}
